package com.hylanda.pb.service;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.ColumnMapRowMapper;
import org.springframework.stereotype.Service;
import com.hylanda.pb.dao.ReportModelDao;
import com.hylanda.pb.model.ReportModel;
import com.hylanda.pb.service.common.ConstantHelper;
import com.hylanda.util.http.OkHttpUtils;
/** 
 * @author zhangy
 * @E-mail:blackoon88@gmail.com 
 * @qq:846579287
 * @version created at：2018年3月2日 上午9:54:37 
 * note
 */
@Service

public class PBAppService {
	@Autowired
	private ReportModelDao reportModelDao;
	@Autowired
	private OkHttpUtils okHttpUtils;
	public Map<String, Object> getReportModelByInstanceId(String instanceId) {
		String sql="select reportID,datasetID,collectionName,workspaceID,filename,database_name,processorId,tableName,model,page,access_key,displayName,importID,report_type from sys_report_model where report_type=? and processorId=?";
		List<Map<String, Object>> list=reportModelDao.getTemplate().query(sql, new Object[]{"azure",instanceId}, new ColumnMapRowMapper());
		if (list != null && list.size() > 0) {
			Map<String, Object> map = list.get(0);
			return map;
		} else {
			return null;
		}
		
	}

	public String updateReportModel(ReportModel model,String reportID) {
		//更新报表模型记录的reportID和displayName
		String sql="update sys_report_model set model=? ,displayName=?,importID=?,page=?,reportID=? where processorId=?";
		int i=reportModelDao.executeUpdate(sql, new Object[]{model.getModel(),model.getDisplayName(),model.getImportID(),model.getPage(),reportID,model.getProcessorId()});
		if(i==0){
			return ConstantHelper.RESPONSE_FAIL;
		}else{
			return ConstantHelper.RESPONSE_SUCCESS;
		}
	}
}
